package com.longmen.service.impl;

import com.longmen.constant.MessageConstant;
import com.longmen.exception.AccountNotFoundException;
import com.longmen.exception.PasswordErrorException;
import com.longmen.mapper.UserMapper;
import com.longmen.pojo.entity.User;
import com.longmen.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 用户登录
     * @param user
     * @return
     */
    public User login(User user) {
        User user1 = userMapper.getByUserName(user.getUserName());
        if (user1 == null){
            throw new AccountNotFoundException(MessageConstant.ACCOUNT_NOT_FOUND);
        }
        if (!user.getPassWord().equals(user1.getPassWord())){
            throw new PasswordErrorException(MessageConstant.PASSWORD_ERROR);
        }
        user1.setPassWord("********");
        return user1;
    }
}
